package py.com.fms.fms.persistence.services;

import java.sql.SQLException;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

import py.com.fms.fms.bean.TypeOfPayAndCollectionHeadBean;
import py.com.fms.fms.bean.TypeOfPayAndCollectionDetBean;
import py.com.fms.exception.CommonException;
import py.com.fms.persistence.services.FmsServices;

public class TypeOfPayAndCollectionServices extends FmsServices {

	public TypeOfPayAndCollectionServices(SqlMapClient client) {
		super(client);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * Returns an List object with all data of the Entity Header. 
	 *
	 * @return      a list with all data
	 */
	@SuppressWarnings("unchecked")
	public List<TypeOfPayAndCollectionHeadBean> getAllTypeOfPayAndColletionHead() throws CommonException{
		List<TypeOfPayAndCollectionHeadBean> queryForList;
		try {
			
			//[[ queryForList is an implemented interface of iBatis]] 
			
			queryForList = (List<TypeOfPayAndCollectionHeadBean>)this.getConfig().queryForList("typeOfPayAndColletion.getAllTypeOfPayAndColletionHead");
			return queryForList;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	

	public TypeOfPayAndCollectionHeadBean getTypeOfPayAndColletionHeadByInsId(Long idHead) throws CommonException{
		TypeOfPayAndCollectionHeadBean queryForObject;
		try {
			
			//[[ queryForList is an implemented interface of iBatis]] 
			
			queryForObject = (TypeOfPayAndCollectionHeadBean)this.getConfig().queryForObject("typeOfPayAndColletion.getTypeOfPayAndColletionHeadByInsId", idHead);
			return queryForObject;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	
	
	/**
	 * Returns an List object with all data of the Entity Details. 
	 *
	 * @return      a list with all data
	 */
	@SuppressWarnings("unchecked")
	public List<TypeOfPayAndCollectionDetBean> getAllTypeOfPayAndColletionDet() throws CommonException{
		List<TypeOfPayAndCollectionDetBean> queryForList;
		try {
			
			//[[ queryForList is an implemented interface of iBatis]] 
			
			queryForList = (List<TypeOfPayAndCollectionDetBean>)this.getConfig().queryForList("typeOfPayAndColletion.getAllTypeOfPayAndColletionDet");
			return queryForList;
			
		} catch (SQLException e) {
			throw new CommonException(e);
		}
	}
	
	
	/**
	 * Insert a Header Record. 
	 * The passed argument is:
	 * <p>
	 * - A entity Object containing the header Fields
	 * 
	 * @param  		the header entity bean(TypeOfPayAndCollectionHeadBean)
	 */
	public void saveNewTypeOfPayAndCollectionHead(TypeOfPayAndCollectionHeadBean typeOfPayAndCollectionHead) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().insert("typeOfPayAndColletion.insTypeOfPayAndColletionHead", typeOfPayAndCollectionHead);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	/**
	 * Insert Detail Record. 
	 * The passed argument is:
	 * <p>
	 * - A entity Object containing the detail fields including the header id
	 * 
	 * @param  		the detail entity bean(TypeOfPayAndCollectionDetBean)
	 */
	public void saveNewTypeOfPayAndCollectionDet(TypeOfPayAndCollectionDetBean typeOfPayAndCollectionDet) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().insert("typeOfPayAndColletion.insTypeOfPayAndColletionDet", typeOfPayAndCollectionDet);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	
	/**
	 * Update a Header Record. 
	 * The passed argument is:
	 * <p>
	 * - A entity Object containing the header Fields
	 * 
	 * @param  		the header entity bean(TypeOfPayAndCollectionHeadBean)
	 */
	public void updateTypeOfPayAndCollectionHead(TypeOfPayAndCollectionHeadBean typeOfPayAndCollectionHead) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().update("typeOfPayAndColletion.udpTypeOfPayAndColletionHeadById", typeOfPayAndCollectionHead);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}
	
	
	/**
	 * update a Detail Record. 
	 * The passed argument is:
	 * <p>
	 * - A entity Object containing the detail fields including the header id
	 * 
	 * @param  		the detail entity bean(TypeOfPayAndCollectionDetBean)
	 */
	public void updateTypeOfPayAndCollectionDet(TypeOfPayAndCollectionDetBean typeOfPayAndCollectionDet) throws CommonException{
		try {
			this.getConfig().startTransaction();
			this.getConfig().update("typeOfPayAndColletion.udpTypeOfPayAndColletionDetById", typeOfPayAndCollectionDet);
			this.getConfig().commitTransaction();
		} catch (SQLException e) {
			throw new CommonException(e);
		} finally {
			try {
				this.getConfig().endTransaction();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new CommonException(e);
			}
		}
	}

}
